日期:2014-05-19  浏览次数:20805 次

myeclipse中java跳转问题。
package ch4;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class Manager extends HttpServlet {  

public Manager() 
{ super(); }  
//destroy()方法  
public void destroy() 
{ super.destroy(); }  
//doGet()方法  
public void doGet(HttpServletRequest request, HttpServletResponse response)  
throws ServletException, IOException {  
//设置页面内容类型  
response.setContentType("text/html;charset=GBK");  
if (request.getParameter("action") != null) 
//判断操作类型 {  
//获取请求中action参数值  
String action =request.getParameter("action"); { if action.equals("addBook")) 
//添加操作  
{  
//参数值为addBook,响应页面为add.jsp  
response.sendRedirect("add.jsp"); }  
else if (action.equals("selBook")) 
//查询操作  
{  
//参数值为selBook,响应页面为select.jsp  

response.sendRedirect("select.jsp");  
} else if (action.equals("exit"))
//注销操作 {  
//参数值为exit,响应页面为login.jsp  
response.sendRedirect("login.jsp");  
} }  
//doPost()方法  
public void doPost(HttpServletRequest request, HttpServletResponse response)  
throws ServletException, IOException {  
doGet(request, response); }  
//init()方法  
public void init() throws ServletException { }  
}

在myeclipse中 红色部分总是说string can not resolved,action can not resolved。




------解决方案--------------------
你这明显是doGet方法中,括号,大括号不匹配。
Java code
// doGet()方法
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        //设置页面内容类型 
        response.setContentType("text/html;charset=GBK");
        if (request.getParameter("action") != null) {
            //判断操作类型
            //获取请求中action参数值
            String action = request.getParameter("action");
            if (action.equals("addBook")) {//添加操作 
                //参数值为addBook,响应页面为add.jsp 
                response.sendRedirect("add.jsp");
            } else if (action.equals("selBook")) {//查询操作  
                //参数值为selBook,响应页面为select.jsp 
                response.sendRedirect("select.jsp");
            } else if (action.equals("exit")) {//注销操作
                //参数值为exit,响应页面为login.jsp
                response.sendRedirect("login.jsp");
            }
        }
    }